Data is retrieved from a database by querying for it. The query is typically written in a query language that declaratively specifies what is to be retrieved. The query expression is typically processed by a query processor, which determines the query's execution plan, the sequence of steps that will be taken to retrieve the requested data. There can be more than one query plan for a particular query, each returning the same results but having different execution plans. The database server typically chooses the execution plan that is expected to yield the results in the shortest possible time, called query optimization.
Debugging query expressions can be challenging, in part due to the declarative nature of a query expression. As a result, it is hard to visualize the data flowing through different stages of query execution, e.g., filtering, projection, sorting and so on. Moreover, query execution can be deferred, which means that the actual execution of the query can take place at a different time and in a different context than that in which the query is defined.